﻿#region Using directives

using System;
using System.Text;
using System.CodeDom;
using System.Collections.Generic;

using Weazel.Gezel.Model;

#endregion

namespace Weazel.Gezel.Conversions.Model
{
  public class SignalType : SignalTypeBase
  {
    private Signal signal;

    public SignalType(Signal signal, ControllerType controllerType, SoftwareModel softwareModel)
      : base(
        String.Format("Signal_{0}", signal.Name.Replace(".", "_")),
        signal,
        controllerType,
        softwareModel,
        signal.Width,
        signal.Signed)
    {
      this.signal = signal;
      this.BaseTypes.Add(new CodeTypeReference("ISignal"));

      valueField.Comments.Add(new CodeCommentStatement("Caches the signal value."));


    }

    public void PostAnalyzeDependencies()
    {
      // add statement to update cycle field
      evaluateMethod.Statements.Add(Statement.Empty);
      evaluateMethod.Statements.Add(
          new CodeCommentStatement("Mark this entity as valid for this cycle ")
        );
      evaluateMethod.Statements.Add(
          new CodeAssignStatement(
            new CodeFieldReferenceExpression(
              new CodeThisReferenceExpression(),
              cycleField.Name
            ),
            new CodeFieldReferenceExpression(
              new CodeTypeReferenceExpression("Simulator"),
              "CurrentCycle"
            )
          )
        );
    }
  }
}

